/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge.major;

import java.util.Collection;
import ru.jSkyRoom.bridge.sub.MagicEffectReferenceBridge;
import ru.jSkyRoom.interfaces.major.JSkyMagicItem;
import ru.jSkyRoom.interfaces.sub.MagicEffectReference;
import skyproc.MagicEffectRef;
import skyproc.MagicItem;

/**
 *
 * @author Rakev
 */
public class MagicItemBridge<E extends MagicItem> extends DescriptionedMajorBridge<E> implements JSkyMagicItem {

    public MagicItemBridge(E adapting) {
        super(adapting);
    }

    @Override
    public Collection<MagicEffectReference> getMagicEffects() {
        return (Collection) getBridgeFactory().createBridges(getRawObject().getMagicEffects());
    }

    @Override
    public void addMagicEffect(MagicEffectReference magicEffect) {
        if (magicEffect instanceof MagicEffectReferenceBridge) {
            MagicEffectRef rawMagicEffect = ((MagicEffectReferenceBridge) magicEffect).getRawObject();
            getRawObject().addMagicEffect(rawMagicEffect);
        } else {
            throw new IllegalArgumentException("Only bridge supported.");
        }
    }

    @Override
    public void removeMagicEffect(MagicEffectReference magicEffect) {
        if (magicEffect instanceof MagicEffectReferenceBridge) {
            MagicEffectRef rawMagicEffect = ((MagicEffectReferenceBridge) magicEffect).getRawObject();
            getRawObject().removeMagicEffect(rawMagicEffect);
        } else {
            throw new IllegalArgumentException("Only bridge supported.");
        }
    }
}
